<template>
	<view class="page">
		<uni-card title="安全隐患详情">
			<view class="detail" v-for="(val, key, index) in detailInfo" :key="key">
				<text class="label">{{ val.name }}:</text>
				<text class="field">{{ val.value }}</text>
			</view>
		</uni-card>
	</view>
</template>

<script>
export default {
	data() {
		return {
			detailInfo: {
				risk_code: { name: '编号', value: '' },
				risk_name: { name: '隐患名称', value: '' },
				risk_level: { name: '隐患等级', value: '' },
				risk_sort: { name: '隐患类别', value: '' },
				risk_reason: { name: '原因分析', value: '' },
				risk_control_measure: { name: '关联的风险控制措施', value: '' },
				risk_result: { name: '关联的后果', value: '' },
				risk_src: { name: '来源', value: '' },
				risk_find_time: { name: '发现时间', value: '' },
				correct_dept: { name: '整改单位/部门', value: '' },
				correct_time: { name: '整改时间', value: '' },
				correct_measure: { name: '整改措施', value: '' },
				correct_fund: { name: '整改资金', value: '' },
				resp_plan: { name: '应急预案', value: '' },
				measure_verifier: { name: '措施验证人', value: '' },
				measure_verify_time: { name: '措施验证时间', value: '' },
				manage_effect_verify: { name: '治理效果验证情况', value: '' },
				is_close: { name: '是否关闭', value: '' },
				close_time: { name: '关闭时间', value: '' }
			}
		}
	},
	onLoad(options) {
		console.log('detail: ', options)
		this.detailId = options.id || 0

		this.getRiskDetail()
	},
	onReady() {},
	methods: {
		async getRiskDetail() {
			const params = {
				id: this.detailId
			}

			try {
				const res = await uni.$uu.Api.getRiskDetail(params)

				console.log(res)

				if (res.code === 100) {
					Object.entries(this.detailInfo).map(([key, val], index) => {
						this.detailInfo[key].value = Object.values(res.content)[index]
					})
				}
			} catch (err) {
				console.log(err)
			}
		}
	}
}
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
